<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
	<script type="text/javascript" src="js/analytics.js"></script>
	<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
	<script type="text/javascript">
	</script>
	<script type="text/javascript">
		$(function(){
			ga('create', 'UA-45859822-1', {
				  'cookieDomain': 'auto'
				});	
			
			sendMessageToExtension();

			$('#goNow').on('click', function(){
				window.open('', '_self', '');
				window.close();
			});
			
		});
		
		function sendMessageToExtension(){
			if(window.location.search.length === 0){
				ga('send', 'pageview', {
					'page' : '/facebook.html',
					'title' : 'Facebook Auth'
				});
				
				var runtimeOrExtension = chrome.runtime && chrome.runtime.sendMessage ? 'runtime' : 'extension';
				
				// send the message to the store extension
				try {
					chrome[runtimeOrExtension].sendMessage('jpajemhbgnpengoegcicnbbakidampaj', {}, sendMessageResponse);
				}
				catch (err) {
					console.log(err.message);
				}
		
				// send the message to the debug extension
				try {
					chrome[runtimeOrExtension].sendMessage('jghfdcpjihdllimebedhfoibipfhghbi', {}, sendMessageResponse);
				}
				catch (err) {
					console.log(err.message);
				}
		
				window.close();
			}
			else{
				ga('send', 'pageview', {
					'page' : '/facebook.html' + window.location.search,
					'title' : 'Facebook Auth'
				});
				
				$('#purpose').html('<p>You must allow the Simple Birthday Reminder app to access your Facebook account if you want to see your friends\' birthdays</p>');
			}
			
		}
		
		function sendMessageResponse(response){
			console.log(response);
		}		
	
	</script>
	
	<link rel="stylesheet" href="styles.css">
</head>
<body>

	<div style="width: 400px; margin: 0 auto; padding: 5px; border: 1px solid black;">
		<div id="purpose">
			<p>The purpose of this page is to pass the authentication
				information from facebook to the Simple Birthday Reminder.</p>
			<p>It should automatically close.</p>
		</div>
		<div style="text-align: center;"><input type="button" id="goNow" value="Close Window" /></div>
	</div>


</body>
</html>